package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.WorkRelatedBean;
import com.renwei.yunlong.utils.DateTimeUtils;
import com.renwei.yunlong.utils.StringUtils;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 工单信息  相关 --adapter
 * <p>
 * Created by Administrator on 2017/9/6.
 */

public class WorkRelateAdapter extends BaseRecyclerViewAdapter<WorkRelatedBean.Rows> {

    public WorkRelateAdapter(Context context) {
        super(context);
    }

    @Override
    public WorkRelateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_work_relate, parent, false);
        return new WorkRelateViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {

        final WorkRelateViewHolder holder = (WorkRelateViewHolder) rholder;

        final WorkRelatedBean.Rows rows = mList.get(position);

        holder.tvTitleContent.setText(StringUtils.value(rows.getTitle()));
        String contentName = StringUtils.value(rows.getCompanyName()) + " / " + StringUtils.value(rows.getSendUserName());
        holder.tvName.setText(contentName);
        holder.tvTime.setText(DateTimeUtils.getMMddHHmm(rows.getSendDate().replace("T", " ")));
        // 主副工单
        if ("2".equals(rows.getIsLeader())) {
            holder.tvLeader.setVisibility(View.VISIBLE);
            holder.tvLeader.setText("主");
            holder.tvLeader.setBackgroundResource(R.drawable.shape_card_e9981f);
        } else if ("3".equals(rows.getIsLeader())) {
            holder.tvLeader.setVisibility(View.VISIBLE);
            holder.tvLeader.setText("副");
            holder.tvLeader.setBackgroundResource(R.drawable.shape_card_5cc9ff);
        } else {
            holder.tvLeader.setVisibility(View.GONE);
        }

        // 工单状态（0未指派 3：已指派 4：处理中 5已关闭,7挂起 ,9待确认，10已解决11已取消 16出发中 17已到达 18未指派）
        if ("0".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("未指派");
        } else if ("3".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_76c56d);
            holder.button.setText("已指派");
        } else if ("4".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e9981f);
            holder.button.setText("处理中");
        } else if ("5".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_999691);
            holder.button.setText("已关闭");
        } else if ("7".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("挂起");
        } else if ("9".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("待确认");
        } else if ("10".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_76c56d);
            holder.button.setText("已解决");
        } else if ("11".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_999691);
            holder.button.setText("已取消");
        } else if ("16".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("出发中");
        } else if ("17".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_76c56d);
            holder.button.setText("已到达");
        } else if ("18".equals(rows.getNowStat())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("未指派");
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnItemClickLitener.onItemClick(view, position);
            }
        });
    }


    class WorkRelateViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tv_title_content)
        TextView tvTitleContent;
        @Bind(R.id.button)
        TextView button;
        @Bind(R.id.tv_leader)
        TextView tvLeader;
        @Bind(R.id.tv_name)
        TextView tvName;


        public WorkRelateViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
